package com.lovo.web.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.commom.remoteMethod.ISysProductRemote;
import com.lovo.commom.util.SnowIdUtils;
import com.lovo.web.bean.EsBean;
import com.lovo.web.bean.ProductBean;
import com.lovo.web.mapper.IEsMapper;
import com.lovo.web.mapper.IProductMapper;
import com.lovo.web.service.IEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class EsServiceImpl implements IEsService {
      @Autowired
      private IEsMapper esMapper;
      @Autowired
      IProductMapper productMapper;
      @Autowired
      ISysProductRemote productRemote;
      @Override
      public void add(EsBean esBean) {
            //添加虚拟
            esBean.setNewsId(SnowIdUtils.uniqueLongHex());
            esMapper.save(esBean);
            //添加商品信息的雪花id
            QueryWrapper<ProductBean> qw = new QueryWrapper<>();
            qw.eq("p_productName",esBean.getProductName());
            ProductBean productBean = productMapper.selectOne(qw);
            productBean.setSnowId(esBean.getNewsId());
            productBean.setStatus(4);
            productMapper.updateById(productBean);

            productRemote.addSnowId(productBean.getProductName(), esBean.getNewsId());
      }

      @Override
      public EsBean findContext(String id) {
            return esMapper.findByNewsId(id);
      }


}
